package com.googlecode.lazyrecords.berkeleydb;

import com.googlecode.lazyrecords.Record;
import com.googlecode.totallylazy.CloseableList;
import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Predicate;
import com.googlecode.totallylazy.Sequence;
import com.sleepycat.je.Database;

import java.util.Iterator;

import static com.googlecode.totallylazy.Predicates.always;
import static com.googlecode.totallylazy.Predicates.and;

public final class JeSequence extends Sequence<Record> {
    private final CloseableList closeables;
    private final Table table;
    private final Option<JeTransaction> transaction;
    private final Predicate<? super Record> predicate;

    public JeSequence(final CloseableList closeables, final Table table, Option<JeTransaction> transaction) {
        this(closeables, table, transaction, always());
    }

    public JeSequence(CloseableList closeables, Table table, Option<JeTransaction> transaction, Predicate<? super Record> predicate) {
        this.closeables = closeables;
        this.table = table;
        this.transaction = transaction;
        this.predicate = predicate;
    }

    @Override
    public Iterator<Record> iterator() {
        return closeables.manage(new CursorIterator(table, transaction, predicate));
    }

//    @Override
//    public Sequence<Record> filter(Predicate<? super Record> predicate) {
//        return new JeSequence(closeables, table, transaction, predicate);
//    }
}
